/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package anivis.base;

import java.util.Date;
import java.util.GregorianCalendar;
import prefuse.util.TimeLib;
/**
 *
 * @author urp
 */
public class TimeInterval {
  
  private Date begin;
  private Date end;
  
  public TimeInterval()
  {
    begin = new GregorianCalendar(2000,1,1).getTime();
    end   = new GregorianCalendar(1900,1,1).getTime();
  }
  public TimeInterval(Date aBegin,Date anEnd)
  {
    begin = aBegin;
    end   = anEnd;
  }
  
  public long getBeginTime() 
  { 
    return begin.getTime(); 
  }
  
  public long getEndTime() 
  {
    return end.getTime(); 
  }

  public Date getBegin() 
  { 
    return begin; 
  }
  
  public Date getEnd()
  {
    return end; 
  }
  
  public boolean isValid() 
  {
    return !begin.after(end);
  }
  
  public boolean contains(Date date)
  {
    return date.after(begin) && date.before(end); 
  }
  
  public long getLength(int field)
  {
    return TimeLib.getUnitsBetween(begin.getTime(), end.getTime(), field);
  }
  
  public long getLengthInMillis()
  {
    return end.getTime()-begin.getTime();
  }
}
